package com.youlv.yl.dao;

import com.youlv.yl.dto.MoodDetailDto;
import com.youlv.yl.entity.mood.UserMood;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fenghe
 * @since 2022-01-15
 */
@Repository
public interface UserMoodDao extends BaseMapper<UserMood> {

    @Select("select um.*, ifnull(ml.likes, 0) likes, ifnull(mf.forwards, 0) forwards " +
            "from t_user_mood um " +
            "left join(select count(*) likes, umid from t_mood_like group by umid) ml " +
            "on um.id = ml.umid " +
            "left join (select count(*) forwards, fumid from t_mood_forward group by fumid) mf " +
            "on um.id = mf.fumid where um.id = #{id}")
    MoodDetailDto selectDetail(Long id);
}
